import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import ElementUI from 'element-ui'
import axios from './common/Api'
import 'element-ui/lib/theme-chalk/index.css'


// 引入封装的过滤器
import * as filters from './filters' // global filters
// import { VueJsonp  } from 'vue-jsonp'

// Vue.use(VueJsonp) // $jsonp被挂载到vue原型上,可直接使用vm.$jsonp()


// Vue.filter('functionName',function)
// register global utility filters
Object.keys(filters).forEach(key => {
 Vue.filter(key, filters[key]);
});

 // 引入echarts
// import echarts from 'echarts'
// 打印机
// import Print from "vue-print-nb"
// Vue.use(Print)
// Vue.prototype.$print = Print

Vue.prototype.$axios = axios;
// Vue.prototype.$echarts = echarts 

Vue.config.productionTip = false
Vue.use(ElementUI)
ElementUI.Dialog.props.closeOnClickModal.default = false

//格式化日期  格式 yyyy-MM-dd hh:mm:ss
let formatTimes = (row) => {
    if (!row) return '无';
    const date = new Date(row),
        year = date.getFullYear(),
        month = date.getMonth() > 9 ? date.getMonth() + 1 : `0${date.getMonth() + 1}`,
        day = date.getDate() > 9 ? date.getDate() : `0${date.getDate()}`,
        hh = date.getHours() > 9 ? date.getHours() : `0${date.getHours()}`,
        mm = date.getMinutes() > 9 ? date.getMinutes() : `0${date.getMinutes()}`,
        ss = date.getSeconds() > 9 ? date.getSeconds() : `0${date.getSeconds()}`;
    return `${year}-${month}-${day} ${hh}:${mm}:${ss}`;
}

let formatDate = (row) => {
    if (!row) return '无';
    const date = new Date(row),
        year = date.getFullYear(),
        month = date.getMonth() > 9 ? date.getMonth() + 1 : `0${date.getMonth() + 1}`,
        day = date.getDate() > 9 ? date.getDate() : `0${date.getDate()}`;
    return `${year}-${month}-${day}`;
}


let formatState = (row, column) => {
    if (!row.state) return '无';
    let state = "";
    if (row.state == "normal") {
        state = "上架";
    } else if (row.state == "off") {
        state = "下架";
    } else {
        state = "删除";
    }
    return state;
}
let formatDisplayState = (row, column) => {
    if (!row) return '无';
    let state = "";
    if (row == "normal") {
        state = "上架";
    } else if (row == "off") {
        state = "下架";
    }
    return state;
}
let formatisFree = (row, column) => {
    if (!row.isFree) return '无';
    let free = ''
    if (row.isFree == "userFree") {
        free = "是";
    } else if (row.isFree == "userPay") {
        free = "否";
    }
    return free;
}
let formatvipIsFree = (row, column) => {
    if (!row.vipIsFree) return '无';
    let free = ''
    if (row.vipIsFree == "vipFree") {
        free = "是";
    } else if (row.vipIsFree == "vipPay") {
        free = "否";
    }
    return free;
}
let formatculumSeries = (row, column) => {
    if (!row.isCurriculumSeries) return '无';
    let free = ''
    if (row.isCurriculumSeries == "yes") {
        free = "是";
    } else if (row.isCurriculumSeries == "no") {
        free = "否";
    }
    return free;
}

Vue.prototype.formatculumSeries = formatculumSeries;
Vue.prototype.formatTimes = formatTimes;
Vue.prototype.formatDate = formatDate;
Vue.prototype.formatvipIsFree = formatvipIsFree;
Vue.prototype.formatisFree = formatisFree;
Vue.prototype.formatDisplayState = formatDisplayState;
Vue.prototype.formatState = formatState;


new Vue({
    router,
    store,
    render: h => h(App)
}).$mount('#app')